<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/common/header.jsp"%>
<a href="" title="短信管理——短信记录"></a>
<script type="text/javascript">

Ext.onReady(function(){
    Ext.BLANK_IMAGE_URL = ' ../../js/ext/images/default/s.gif'; 
    // ---------------------- Global vars and functions------------------------------
    Ext.SERVER = '<c:url value="/"/>';
    
    // ------------ 得到url参数-------------------------   
    function GetUrlParms()    
    {
         var args=new Object();   
         var query=location.search.substring(1);//获取查询串   
         var pairs=query.split("&");//在逗号处断开   
         for(var    i=0;i<pairs.length;i++)   
         {   
             var pos=pairs[i].indexOf('=');//查找name=value   
             if(pos==-1)   continue;//如果没有找到就跳过   
             var argname=pairs[i].substring(0,pos);//提取name   
             var value=pairs[i].substring(pos+1);//提取value   
             args[argname]=unescape(value);//存为属性   
        }
         return args;
    }


    var selectForm = new Ext.form.FormPanel({
        region:'north',
        title: '查询条件',
        height:285,
        buttonAlign:'center',
        bodyStyle: 'padding:5px',
        frame: true,
        layout: 'fit',
        items: [{
            layout: 'column',
            items: [
                    {
                        columnWidth: .5,
                        layout: 'form',
                        labelWidth: 100,
                        defaultType: 'textfield',
                        defaults: {
                            width: 180,
                            msgTarget: 'side'
                        },
                        items: [
                            {
                                name: 'id',
                                inputType: 'hidden',
                                fieldLabel: '编号'
                            },
                            {
                                name: 'userRealName',
                                fieldLabel: '用户名'
                            },
                           {
                                           fieldLabel: '开始时间',
			                                sortable: true,
			                                xtype: 'datefield',
			                                readOnly : true,
			                                format : 'Y-m-d',
											anchor : '90%' ,
			                                name: 'beginTime'
                                        }
                        ]
                    },
                    {
                        columnWidth: .5,
                        layout: 'form',
                        labelWidth: 100,
                        defaultType: 'textfield',
                        defaults: {
                            width: 180,
                            msgTarget: 'side'
                        },
                        items: [
                            {
                                name: 'e2qSmDepartmentName',
                                fieldLabel: '用户部门'
                            },
                            {
                                           fieldLabel: '结束时间',
			                                sortable: true,
			                                xtype: 'datefield',
			                                readOnly : true,
			                                format : 'Y-m-d',
			                                anchor : '90%' ,
			                                name: 'endTime'
                                        }
                        ]
                    }
                ]
        }],
        buttons: [
            {
                text: '查询',
                handler: function(){
                    smsStore.removeAll();
                    smsStore.load({
				        params:{start:0, limit:10},
				        waitMsg: 'loading...',
			
				        failure: function() {
				            Ext.Msg.alert('提示', '读取数据失败！');
				        }
				    });
                }
            },
            {
                text: '重置',
                handler: function(){
                    selectForm.getForm().reset();
                    
                }
            }
        ]
    });


// --------------- grid store -------------------

    var smsStore = new Ext.data.JsonStore({
        url: '<c:url value="/sms/smsList.do" />',
        root: 'data',
        totalProperty: 'totalCount',
        idProperty: 'id',
        autoDestroy: true,
        listeners :{  
            beforeload :{  
                fn : function(smsStore){  
                    Ext.apply(smsStore.baseParams, selectForm.getForm().getValues());   
                }  
            }  
        },
        fields: [
            { name: 'id' },
            { name: 'shcSendUserId' },
            { name: 'shcSendUserName' },
            { name: 'shcReceiverId' },
            { name: 'shcReceiverMobiles' },
            { name: 'shcContent' },
            { name: 'shcNode' },
        ]
    });

 var userStore = new Ext.data.JsonStore({
        url: '<c:url value="/sms/userList.do" />',
        root: 'data',
        totalProperty: 'totalCount',
        idProperty: 'id',
        autoDestroy: true,
        fields: [
            { name: 'id' },
            { name: 'userRealName' },
            { name: 'e2qSmDepartmentId' },
            { name: 'e2qSmDepartmentName' }
        ]
    });




    function storeLoad (){
        userStore.removeAll();
        userStore.load({
	        params:{start:0, limit:10},
	        waitMsg: 'loading...',

	        failure: function() {
	            Ext.Msg.alert('提示', '读取数据失败！');
	        }
	    });
    };


   
    
  // --------------- form and window --------------------  
   var smsForm = new Ext.form.FormPanel({
   		title: '短信详情',
        bodyStyle: 'padding:5px',
        height:285,
        frame: true,
        items: [{
            items: [
                    {
                        layout: 'form',
                        defaultType: 'textfield',
                        defaults: {
                            msgTarget: 'side'
                        },
                        items: [
                             {
                                fieldLabel: '编号',
                                sortable: true,
                                inputType: 'hidden',
                                name: 'id'
                            },
                            {
                                fieldLabel: '发送人',
                                sortable: true,
                                name: 'shcSendUserName'
                            },
                            {
                                name: 'shcReceiverMobiles',
                                sortable: true,
                                fieldLabel: '接收号码'
                            },
                            new  Ext.form.TextArea({    //TextArea
	                          fieldLabel:'短信内容',
	                          name:'shcContent',                         
	                          height:90,
	                          width: 300,                          
	                          id: 'shcContent',                          
	                        }),
                            new  Ext.form.TextArea({    //TextArea
	                          fieldLabel:'备注',
	                          name:'shcNode',                         
	                          height:90,
	                          width: 300,                          
	                          id: 'shcNode',                          
	                        })
                        ]
                    }
                ]
        }]
    }); 


   



    // --------------- grid --------------------

    var smsGrid = new Ext.grid.GridPanel({
        region:'center',
        store: smsStore,
        title: '短信列表',
        height:285,
        trackMouseOver: false,
        disableSelection: false,
        loadMask: true,
        viewConfig: {
            forceFit: true
        },
        columns: [
            {
                header: '编号',
                hidden: true,
                sortable: true,
                dataIndex: 'id'
            },
            {
                header: '发送人id',
                hidden: true,
                sortable: true,
                dataIndex: 'shcSendUserId'
            },
            {
                header: '发送人',                
                sortable: true,
                dataIndex: 'shcSendUserName'
            },
            {
                header: '收信人id',
                hidden: true,
                sortable: true,
                dataIndex: 'shcReceiverId'
            },
            {
                header: '收信号码',
                sortable: true,
                dataIndex: 'shcReceiverMobiles'
            },
            {
                header: '短信内容',
                sortable: true,
                dataIndex: 'shcContent'
            },
            {
                header: '备注',
                sortable: true,
                dataIndex: 'shcNode'
            }
        ],
        
        bbar: new Ext.PagingToolbar({
            pageSize: 10,
            store: smsStore,
            displayInfo: true,
            displayMsg: '显示: {0} - {1} / 总数: {2}',
            emptyMsg: '没有记录'
        })    
    });
    
    var userGrid = new Ext.grid.GridPanel({
        region:'center',
        height:285,
 //       width: 334,
        store: userStore,
        title: '选择查询用户',
        trackMouseOver: false,
        disableSelection: false,
        loadMask: true,
        viewConfig: {
            forceFit: true
        },
        columns: [
            {
                header: '编号',
                hidden: true,
                sortable: true,
                dataIndex: 'id'
            },
            {
                header: '姓名',
                sortable: true,
                dataIndex: 'userRealName'
            },
            {
                header: '所在部门id',
                hidden: true,
                sortable: true,
                dataIndex: 'e2qSmDepartment'
            },
            {
                header: '所在部门',
                sortable: true,
                dataIndex: 'e2qSmDepartmentName'
            }
        ],
        
        bbar: new Ext.PagingToolbar({
            pageSize: 10,
            store: userStore,
            displayInfo: true,
            displayMsg: '显示: {0} - {1} / 总数: {2}',
            emptyMsg: '没有记录'
        })    
    });

    
    // --------------- viewport --------------------

    var viewport = new Ext.Viewport({
         modal: true,
        layout: 'fit',
        plain: true,
        gridFlag:'undefined',
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: [{
                        layout: 'form',
                        items: [{
                                layout: 'column',
                                items: [
                                        {
                                            columnWidth: .5,
                                            layout: 'form',
                                            items: [
                                               userGrid,
                                               smsGrid
                                               
                                            ]
                                        },
                                        {
                                            columnWidth: .5,
                                            layout: 'form',
                                            items: [
                                                selectForm,
                                                smsForm
                                            ]
                                        }
                                    ]
                            }
                        ]
                    }
                    ]
       
    });

    // --------------- init --------------------
	storeLoad();
	userGrid.addListener(
        'rowclick',
        function(){
        	 var record = userGrid.getSelectionModel().getSelected();
            if(record != null){                
                selectForm.getForm().loadRecord(record);      
	            }
        }
    );
    smsGrid.addListener(
        'rowclick',
        function(){
        	 var record = smsGrid.getSelectionModel().getSelected();
            if(record != null){                
                smsForm.getForm().loadRecord(record);      
	            }
        }
    );

});
</script>
<%@ include file="/WEB-INF/views/common/footer.jsp"%>
